//                            _ooOoo_  
//                           o8888888o  
//                           88" . "88  
//                           (| -_- |)  
//                            O\ = /O  
//                        ____/`---'\____  
//                      .   ' \\| |// `.  
//                       / \\||| : |||// \  
//                     / _||||| -:- |||||- \  
//                       | | \\\ - /// | |  
//                     | \_| ''\---/'' | |  
//                      \ .-\__ `-` ___/-. /  
//                   ___`. .' /--.--\ `. . __  
//                ."" '< `.___\_<|>_/___.' >'"".  
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |  
//                 \ \ `-. \_ __\ /__ _/ .-` / /  
//         ======`-.____`-.___\_____/___.-`____.-'======  
//                            `=---='  
//  
//         .............................................  
//                  佛祖保佑             永无BUG 
//          佛曰:  
//                  写字楼里写字间，写字间里程序员；  
//                  程序人员写程序，又拿程序换酒钱。  
//                  酒醒只在网上坐，酒醉还来网下眠；  
//                  酒醉酒醒日复日，网上网下年复年。  
//                  但愿老死电脑间，不愿鞠躬老板前；  
//                  奔驰宝马贵者趣，公交自行程序员。  
//                  别人笑我忒疯癫，我笑自己命太贱；  
//                  不见满街漂亮妹，哪个归得程序员？  


#include "ResWulinFight2Message.h"

const int ResWulinFight2Message::_ID = 110210;

ResWulinFight2Message::ResWulinFight2Message(){
	//0:正常取数据  1:淘汰赛未开启
	state =0;
	//0:可鼓励  1:已经鼓励过不可鼓励
	encourage =0;
}
ResWulinFight2Message::~ResWulinFight2Message()
{
reset();
}

/**
 * 读取字节缓存
 */
bool ResWulinFight2Message::read_from(ByteBuf& buf)
{
	//第一轮 1/8决赛 (共8对)
	short round1_length = readInt16(buf);
	for (int i = 0; i < round1_length; i++) {
		auto bean =new WulinFightPair();
		readBean(buf, *bean);
		round1.push_back(bean);
	}
	//第二轮 1/4决赛 (共4对)
	short round2_length = readInt16(buf);
	for (int i = 0; i < round2_length; i++) {
		auto bean =new WulinFightPair();
		readBean(buf, *bean);
		round2.push_back(bean);
	}
	//第三轮 半决赛 (共2对)
	short round3_length = readInt16(buf);
	for (int i = 0; i < round3_length; i++) {
		auto bean =new WulinFightPair();
		readBean(buf, *bean);
		round3.push_back(bean);
	}
	//三四名赛
	short round4_length = readInt16(buf);
	for (int i = 0; i < round4_length; i++) {
		auto bean =new WulinFightPair();
		readBean(buf, *bean);
		round4.push_back(bean);
	}
	//决赛
	short round5_length = readInt16(buf);
	for (int i = 0; i < round5_length; i++) {
		auto bean =new WulinFightPair();
		readBean(buf, *bean);
		round5.push_back(bean);
	}
	//0:正常取数据  1:淘汰赛未开启
	state = readInt32(buf);
	//0:可鼓励  1:已经鼓励过不可鼓励
	encourage = readInt32(buf);
	
	return true;
}

/**
 * 写入字节缓存
 */
bool ResWulinFight2Message::write_to(ByteBuf& buf)
{
	//第一轮 1/8决赛 (共8对)
	writeShort(buf, round1.size());
	for (int i = 0; i < round1.size(); i++) {
		writeBean(buf, *round1[i]);
	}
	//第二轮 1/4决赛 (共4对)
	writeShort(buf, round2.size());
	for (int i = 0; i < round2.size(); i++) {
		writeBean(buf, *round2[i]);
	}
	//第三轮 半决赛 (共2对)
	writeShort(buf, round3.size());
	for (int i = 0; i < round3.size(); i++) {
		writeBean(buf, *round3[i]);
	}
	//三四名赛
	writeShort(buf, round4.size());
	for (int i = 0; i < round4.size(); i++) {
		writeBean(buf, *round4[i]);
	}
	//决赛
	writeShort(buf, round5.size());
	for (int i = 0; i < round5.size(); i++) {
		writeBean(buf, *round5[i]);
	}
	//0:正常取数据  1:淘汰赛未开启
	writeInt32(buf, state);
	//0:可鼓励  1:已经鼓励过不可鼓励
	writeInt32(buf, encourage);
	
	return true;
}

int ResWulinFight2Message::getId()
{
  	return _ID;
}



void ResWulinFight2Message::reset(){
for(auto bean : round1){
	if (bean)
	delete bean;
}
round1.clear();
for(auto bean : round2){
	if (bean)
	delete bean;
}
round2.clear();
for(auto bean : round3){
	if (bean)
	delete bean;
}
round3.clear();
for(auto bean : round4){
	if (bean)
	delete bean;
}
round4.clear();
for(auto bean : round5){
	if (bean)
	delete bean;
}
round5.clear();
}


ResWulinFight2Message* ResWulinFight2Message::clone(){
	auto ret=new ResWulinFight2Message();
for(auto bean : round1){
    ret->round1.push_back(bean->clone());
}
for(auto bean : round2){
    ret->round2.push_back(bean->clone());
}
for(auto bean : round3){
    ret->round3.push_back(bean->clone());
}
for(auto bean : round4){
    ret->round4.push_back(bean->clone());
}
for(auto bean : round5){
    ret->round5.push_back(bean->clone());
}
    ret->state=state;
    ret->encourage=encourage;
	return ret;
}